package com.information.service.iml;

import com.alibaba.fastjson.JSONArray;
import com.information.service.StudentService;
import com.information.util.DateUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class StudentServiceIml implements StudentService{

	@Override
	public Page<Record> students(Integer pageNum) {
		return Db.paginate(pageNum, 5, 
				"select a.id,a.addDate,a.update,a.name,a.age,a.sex,a.sfzh,b.banji,c.nianji,d.t_name", 
				"from students_information a join banji b on a.banji_id=b.id join nianji c on a.nianji_id=c.id "
				+ "join banzhuren d on a.banzhuren_id=d.id order by a.addDate desc");
	}

	@Override
	public Record student(int id) {
		return Db.findById("students_information", id);
	}

	@Override
	public boolean updata(Record record) {
		String date=DateUtil.getDefaultCurrentDateTime();
		record.set("update", date);//或者record.set("addDate", new new DateUtil());
		return Db.update("students_information", record);
	}

	@Override
	public boolean delect(int id) {
		return Db.deleteById("students_information", id);
	}

	@Override
	public boolean delect(JSONArray idlist) {
		boolean aa = false;
		for(Object a:idlist) {
			aa=Db.deleteById("students_information", a);
		}
		return aa;
	}

	@Override
	public boolean save(Record record) {
		String date=DateUtil.getDefaultCurrentDateTime();
		record.set("addDate", date);//或者record.set("addDate", new new DateUtil());
		boolean aa=Db.save("students_information", record);
		return aa;
	}

}
